package com.bruce.asurada.sso.exception;

/**
 * 重复注册异常
 * 
 * @author Bruce
 */
public class DuplicateRegistrationException extends RuntimeException {

    private final String field;
    private final String value;

    public DuplicateRegistrationException(String field, String value) {
        super(String.format("%s '%s' 已被注册，请使用其他%s", getFieldName(field), value, getFieldName(field)));
        this.field = field;
        this.value = value;
    }

    public DuplicateRegistrationException(String field, String value, String message) {
        super(message);
        this.field = field;
        this.value = value;
    }

    public String getField() {
        return field;
    }

    public String getValue() {
        return value;
    }

    /**
     * 获取字段中文名称
     */
    private static String getFieldName(String field) {
        switch (field) {
            case "username":
                return "用户名";
            case "mobile":
                return "手机号";
            case "email":
                return "邮箱";
            default:
                return field;
        }
    }
}